﻿#ifndef _CFEATURE_SELECTION_H_H_
#define _CFEATURE_SELECTION_H_H_
#include "udatabase/dll_cfg.h"
#include "udatabase\interface\ifeatureselection.h"
#include "udatabase\geodb\vectorfeatureclass.h"



namespace FD{
	namespace Utility{
		namespace DB{

class CFeatureSelectionPrivate;
/// <summary>
/// 要素选择器，用于存放数据集中被选中的要素ID。
/// </summary>
class FD_DB_Export FeatureSelection : public FD::Utility::DB::Interface::IFeatureSelection
{
public:		
	/// <summary>
	/// 构造函数
	/// </summary>
	/// <param name="fc">要素集</param>
	/// <param name="flag">标记</param>
	/// <returns></returns>
	FeatureSelection(FD::Utility::DB::CVectorFeatureClass *ref_fc,int32 flag);
	friend class CVectorFeatureClass;
	/// <summary>
	/// 默认析构函数
	/// </summary>
	virtual ~FeatureSelection();
public:
	/// <summary>
	/// 获取要素数目
	/// </summary>
	/// <returns>要素数目</returns>
	virtual uint32 getCount() const;
	/// <summary>
	/// 获取要素ID
	/// </summary>
	/// <param name="index">指定索引</param>
	/// <returns>要素ID</returns>
	virtual uint32 getID(uint32 index) const;
	/// <summary>
	/// 获取所有ID
	/// </summary>
	/// <param name="ids">输出，ID数组</param>
	/// <returns>要素ID个数</returns>
	virtual uint32 getIDs(uint32 * ids) const;
	/// <summary>
	/// 判断指定ID是否存在
	/// </summary>
	/// <param name="id">指定ID</param>
	/// <returns>存在，返回索引，不存在，返回-1</returns>
	virtual int32 findID(uint32 id) const;
	/// <summary>
	/// 在选择器中，再查询指定条件要素
	/// </summary>
	/// <param name="filter">指定条件</param>
	/// <returns>要素结果迭代器</returns>
	virtual FD::Utility::DB::Interface::IFeatureIterator* query(FD::Utility::DB::Interface::IQueryFilter* filter) const;
	/// <summary>
	/// 在选择器中，再选择指定条件要素
	/// </summary>
	/// <param name="filter">指定条件</param>
	/// <returns>要素选择器</returns>
	virtual   FD::Utility::DB::Interface::IFeatureSelection* select(FD::Utility::DB::Interface::IQueryFilter* filter) const;
	/// <summary>
	/// 添加指定ID
	/// </summary>
	/// <param name="id">指定ID</param>
	/// <returns>true，成功；false，失败</returns>
	virtual bool addID(uint32 id);
	/// <summary>
	/// 添加ID数组
	/// </summary>
	/// <param name="id">ID数组</param>
	/// <param name="size">ID数组大小</param>
	/// <returns>添加个数</returns>
	virtual uint32 addIDs(uint32 * id,uint32 size);
	/// <summary>
	/// 移除指定索引出的指定个数的ID
	/// </summary>
	/// <param name="index">指定索引</param>
	/// <param name="size">指定大小</param>
	/// <returns>成功移除数目</returns>
	virtual uint32 remove(uint32 index,uint32 size);
	/// <summary>
	/// 移除所有的ID
	/// </summary>
	/// <returns>要素选择器</returns>
	virtual uint32 clear();
	/// <summary>
	/// 取两个选择器的交集ID
	/// </summary>
	/// <param name="set">指定选择器</param>
	/// <returns></returns>
	virtual void intersect(const FD::Utility::DB::Interface::IFeatureSelection* set);
	/// <summary>
	/// 取两个选择器的不同ID
	/// </summary>
	/// <param name="set">指定选择器</param>
	/// <returns></returns>
	virtual void difference(const FD::Utility::DB::Interface::IFeatureSelection* set);
	/// <summary>
	/// 追加指定选择器ID
	/// </summary>
	/// <param name="set">指定选择器</param>
	/// <returns></returns>
	virtual void append(const FD::Utility::DB::Interface::IFeatureSelection* set);
	/// <summary>
	///通过迭代器查询下一条要素
	/// </summary>
	/// <param name="iterator">迭代器</param>
	/// <returns>返回要素</returns>
	  FD::Utility::DB::Interface::IFeature*	nextFeature(const FD::Utility::DB::CFeatureIterator *iterator);
	/// <summary>
	///停止指定迭代器的查询
	/// </summary>
	/// <param name="iterator">迭代器</param>
	/// <returns></returns>
	virtual void	endQuery(const FD::Utility::DB::CFeatureIterator *iterator);

protected:
	FeatureSelection(FD::Utility::DB::CVectorFeatureClass *fc);
	String getRestrictionString() const;
private:
	FeatureSelection(FeatureSelection & obj);
	void fromStream(FD::Kernel::DataStream &stream);
private:
	mutable vector<uint32> m_ids;
	mutable FD::Kernel::ReadWriteLock mLock;
	FD::Utility::DB::CVectorFeatureClass *m_pFC;
	CFeatureSelectionPrivate* mPraviteData;
};



}}} //End of namespaces

#endif  //_CFEATURE_SELECTION_H_H_
